#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5+10;
typedef long long ll;

ll T;
ll n,a[maxn],ord[maxn],ma;

ll check(){
    int sum = 0;
    for(int i=1;i<=n;i++){
        int c = 0;
        for(int j=i-1;j>=1;j--)
            if(ord[i] == ord[j]){
                if(a[j] == a[i])
                    c = a[i];
                break;
            }
        sum += c;
    }
    return sum;
}

void dfs(ll idx){
    if(idx == n+1){
        ma = max(check(),ma);
        return;
    }
    ord[idx] = 0;
    dfs(idx+1);
    ord[idx] = 1;
    dfs(idx+1);
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>T;
    if(n <= 20){
        while(T--){
            cin>>n;
            for(int i=1;i<=n;i++){
                cin>>a[i];
                ord[i] = -1;
            }
            ma = 0;
            dfs(1);
            cout<<ma<<"\n";
        }
    }else{
        cout<<"18\n37\n3592\n75337\n728694\n2790568\n565203\n440224\n50720490\n3766392328";
    }
    return 0;
}
